package com.qf.service.impl;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.qf.base.service.impl.BaseServiceImpl;
import com.qf.entity.Friend;
import com.qf.mapper.IFriendMapper;
import com.qf.service.IFriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author: xbb
 * @Date:2020/4/15
 */
@Service
public class FriendServiceImpl extends BaseServiceImpl<Friend> implements IFriendService {

    @Autowired
    private IFriendMapper friendMapper;

    @Override
    public BaseMapper<Friend> getMapper() {
        return friendMapper;
    }

    @Override
    public void addFriend(Integer fid, Integer tid, int i) {
        //1.单向的添加
        Friend friend = new Friend();
        friend.setFid(fid);
        friend.setUid(tid);
        friend.setStatus(1);

        friendMapper.insert(friend);

        Friend friend1 = new Friend();
        friend1.setFid(tid);
        friend1.setUid(fid);
        friend1.setStatus(1);
        friendMapper.insert(friend1);
    }

    @Override
    public Integer selectIsFriend(Integer tid, Integer fid) {
        Friend friend = new Friend();
        friend.setUid(tid);
        friend.setFid(fid);
        Friend friend1 = friendMapper.selectOne(friend);
        if(friend1!=null){
            return 1;
        }
        return 0;



    }

    @Override
    public List<Friend> getFriendListById(Integer uid) {
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.eq("uid",uid);
        List<Friend> friendList = friendMapper.selectList(wrapper);
        return friendList;
    }
}
